﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SharpDX;
using SharpDX.Direct3D9;
using SharpDX.Direct3D;
using SharpDX.Windows;

using memcolor = SharpDX.Color;


namespace Tails_Animation
{
    public partial class Form1 : Form
    {
        
        [STAThread]
        static void Main()
        {


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Form1 f1 = new Form1();

            PresentParameters presentParams = new PresentParameters();
            presentParams.Windowed = true;
            presentParams.SwapEffect = SwapEffect.Discard;




         Device dev = new Device(new Direct3D(), 0, DeviceType.Hardware, f1.pictureBox1.Handle, CreateFlags.HardwareVertexProcessing, presentParams);

           var vertices = new VertexBuffer(dev, 3 * 20, Usage.WriteOnly, VertexFormat.None, Pool.Managed);
           vertices.Lock(0, 0, LockFlags.None).WriteRange(new[]{
             new CustomVertex.Vertex() { Color = memcolor.Red,Position = new Vector4(0.0f, 0.0f, 0.5f, 1.0f) },
             new CustomVertex.Vertex() { Color = memcolor.Green,Position = new Vector4(100.0f, 0.0f, 0.5f, 1.0f)},
             new CustomVertex.Vertex() { Color = memcolor.Blue,Position = new Vector4(100.0f, 100.0f, 0.5f, 1.0f)}
            });
           vertices.Unlock();
            

           var vertexElems = new[] {
            new VertexElement(0,0,DeclarationType.Float4,DeclarationMethod.Default,DeclarationUsage.PositionTransformed,0),
            new VertexElement(0,16,DeclarationType.Color,DeclarationMethod.Default,DeclarationUsage.Color,0),
            VertexElement.VertexDeclarationEnd};
            

           var vertexDecl = new VertexDeclaration(dev, vertexElems);
            
            RenderLoop.Run(f1, () => {

                dev.Clear(ClearFlags.Target, SharpDX.Color.CornflowerBlue, 1.0f, 0);
                
                dev.BeginScene();
                dev.SetStreamSource(0, vertices, 0, 20);
                dev.VertexDeclaration = vertexDecl;
                dev.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
                dev.EndScene();
                dev.Present();
                
             
            });
           
        }        
        
       

        public Form1()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
            
        }
       
        
       
       
        public void InitializeDevice()
        {
            
            
            
        }
       
       
        
        
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            
            pictureBox1.Invalidate();
        }

        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            
        }

        private void importToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            
        
        
        }
        
        
        
        private void trackBar1_Scroll(object sender, EventArgs e)
        {

        }
        
        private void Form1_Load(object sender, EventArgs e)
        {
            
            
            
        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            trackBar1.Maximum = (int)numericUpDown1.Value - 1;
        }
            
        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {   
            
            Mesh M = new Mesh(pictureBox1.Handle);
            
           
            XFile xf = new XFile(pictureBox1.Handle);
            XFileData xfd = new XFileData(pictureBox1.Handle);
            MessageBox.Show("Success!");
            MessageBox.Show("");

           
            
        }
        
    }
 

}
